package hnair.com.shop.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.ContentFrameLayout;

import hnair.com.shop.R;
import hnair.com.shop.delegates.ShopDelegate;
import me.yokeyword.fragmentation.SupportActivity;

/**
 * Created by liaowei on 2017/11/16.
 * 容器Activity
 */

public abstract class ProxyActivity extends SupportActivity {

    //设置根delegate
    public abstract ShopDelegate setRootDelegate();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化视图
        initContainer(savedInstanceState);
    }

    private void initContainer(@Nullable Bundle savedInstanceState) {
        final ContentFrameLayout container = new ContentFrameLayout(this);
        container.setId(R.id.delegate_container);

        setContentView(container);
        if (savedInstanceState == null) {
            //第一次加载
            loadRootFragment(R.id.delegate_container, setRootDelegate());
        }
    }

    //垃圾回收工作
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //不一定会执行
        System.gc();
        System.runFinalization();
    }
}
